import { GetLikeOrStarList } from "~/api";

export const useContent = () => {
    const dialogStore = useDialogStore();
    const navActive = ref(0);
    const list = ref([]);
    const loading = ref(false);

    const GetList = async () => {
        loading.value = true;
        const res = await GetLikeOrStarList({
            type: dialogStore.midListType,
            type2: navActive.value,
        });
        loading.value = false;
        list.value = res.data;
    };

    const onTabClick = (type) => {
        dialogStore.midListType = type;
        list.value = [];
        GetList();
    };

    const onClose = () => {
        dialogStore.isMidListDialogVisible = false;
    };

    watch(
        () => navActive.value,
        () => {
            list.value = [];
            GetList();
        }
    );

    watch(
        () => dialogStore.isMidListDialogVisible,
        () => {
            if (dialogStore.isMidListDialogVisible) {
                GetList();
            } else {
                list.value = [];
            }
        }
    );

    return {
        list,
        loading,
        navActive,
        GetList,
        onTabClick,
        onClose,
    };
};
